import React from 'react';
import { Toast,InputItem } from 'antd-mobile';

export default class Index extends React.Component {
    constructor(props){
        super(props)
        this.state={
			nickname: props.match.params.nickname,
		}
    }
	componentDidMount(){
		document.title = '修改昵称'
	}
	save(){
		if(this.state.nickname===''){
			return Toast.fail('昵称不能为空!',1)
		}
		if(this.state.nickname===this.props.match.params.nickname){
			return Toast.fail('昵称未改变!',1)
		}
		Toast.loading()
		global.Ajax.hhtc_request("user/editnickname",{nickname: this.state.nickname}).then(data=>{
			Toast.hide()
			if(data.code===1){
				Toast.success(data.msg,1,()=>{
					this.props.history.goBack()
				})
			}else{
				Toast.fail(data.msg,1)
			}
		})
	}
	render(){
		return(
			<div className='set_box' style={{minHeight: '100vh',background: '#F5F5F5',}}>
                <InputItem onChange={(nickname)=>{
					this.setState({
						nickname
					})
				}} clear placeholder={this.state.nickname}></InputItem>
                <p className='save_set' onClick={this.save.bind(this)}>保存设置</p>
			</div>
		)
	}
}
